package com.lagou.boot;

import com.lagou.client.RPCConsumer;
import com.lagou.service.IUserService;
import com.lagou.service.pojo.RpcRequest;

public class ConsumerBoot {

    private static long requestTime;

    //参数定义
    private static final String PROVIDER_NAME = "UserService#sayHello#";

    public static void main(String[] args) throws InterruptedException {

        RpcRequest rpcRequest = createRpcRequest();
        //1.创建代理对象
        IUserService service = (IUserService) RPCConsumer.createProxy(IUserService.class, rpcRequest);
        //2.循环给服务器写数据
        int i = 0;
        while (true) {
            long startTime = System.currentTimeMillis();

            rpcRequest.setRequestId(String.valueOf(i));
            String result = service.transferRpcRequest(rpcRequest);
            Thread.sleep(2000);

            long endTime = System.currentTimeMillis();

            requestTime = (endTime - startTime) / 1000;

            System.out.println(result + "，请求耗时：" + requestTime);
            i++;
        }

    }

    public static RpcRequest createRpcRequest() {
        RpcRequest rpcRequest = new RpcRequest();
        rpcRequest.setClassName("RpcRequest");
        return rpcRequest;
    }
}
